package com.solo.game.snake;

import java.util.Random;

/**
 * 
 * <code>Bonus</code>
 * <p>
 * Bonus描述: 奖励
 * 
 * @version 1.0
 * @author Zangrong.Solo 日期: Dec 13, 2012 3:47:08 PM
 */
public class Bonus {

    private int row;

    private int column;

    private Game game;

    public Bonus(Game game) {

        this.game = game;
    }

    /**
     * 
     * <P>
     * 描述: 创建一个新的奖励
     * 
     * @author Zangrong.Solo 日期: Dec 19, 2012 1:51:36 PM
     */
    public void createBonus() {

        row = new Random().nextInt(this.game.getPreference().getRow());
        column = new Random().nextInt(this.game.getPreference().getColumn());
        // 如果位置被占用
        while (!game.isFieldAvailable(row, column)) {
            row = new Random().nextInt(this.game.getPreference().getRow());
            column = new Random()
                    .nextInt(this.game.getPreference().getColumn());
        }
        game.setFieldColor(row, column, game.getPreference().getBonusColor());
    }

    /**
     * 
     * <P>描述: 判断是否吃到奖励
     * 
     * @author Zangrong.Solo
     * 日期: Dec 19, 2012 2:02:46 PM
     * @param x
     * @param y
     * @return
     */
    public boolean isEat(int x, int y) {
        return x == this.row && y == this.column;
    }

}
